#include "LocalListWidget.h"

LocalListWidget::LocalListWidget(QWidget *parent)
	:QListWidget(parent)
{}

LocalListWidget::~LocalListWidget()
{}

void LocalListWidget::AddItem(const LocalItem & info)
{
	QListWidgetItem *pItem = new QListWidgetItem(this);
	pItem->setSizeHint(QSize(200, 150));
	myListWidget *myItem = new myListWidget();
	QListWidget::addItem(pItem);
	QListWidget::setItemWidget(pItem, myItem);
}

void LocalListWidget::Refresh(const QList<LocalItem>& info)
{
	Clear();
	int nCount = info.size();
	int nSize = nCount > 15 ? 15 : nCount;
	for (int i = 0; i < nSize; i++)
	{
		LocalListWidget::AddItem(info[i]);
	}
	if (nCount > 15)
	{
		this->m_itemList = info.mid(15, nCount - 15);
	}
}

void LocalListWidget::Clear()
{
	QListWidgetItem *pItem = nullptr;
	QWidget *pWidget = nullptr;
	while (QListWidget::count() > 0)
	{
		pItem = QListWidget::takeItem(0);
		pWidget = itemWidget(pItem);
		if (pWidget)
		{
			delete pWidget;
		}
		QListWidget::clear();
		this->m_itemList.clear();
	}
}
